package tripleo.histore;

import tripleo.histore.j1.HiStore_J1;
import tripleo.util.*;

/**
 * Date: Feb 8, 2005
 * Time: 2:37:34 PM
 * <p/>
 * $Id: PersistentSpaceTest.java,v 1.3 2005/10/11 19:22:08 olu Exp $
 */
public class CentennialTest {
	public static void main(String[] args)
	        throws Exception {
		HiStore n = HiStore_J1.New("PersistentSpaceTest");
		new CentennialTest().runOn(n);
	}

	/**
	 * @param n
	 * @throws Exception 
	 */
	public void runOn(HiStore n) throws Exception {
		for (int i = 0; i < 100; ++i) {
			String s = string_of_int(i);
			HiStoreEntry e = n.alloc(s);
			e.contentWriter().write(UT.hexify(i).getBytes());
//			e.contentWriter().close();
			e.commit(null);
		}
		HiStoreEntry e = n.insert("101");
		try {
			e = n.insert("101");
			Assert.not_reached();
			throw new Exception("mark-failure");
		} catch (ConsistencyFailure cf) {
			UT.errW.println("Success in double insert");
		}
	}

	/**
	 * @param i
	 * @return
	 */
	private static String string_of_int(int i) {
		return Integer.toString(i);
	}
}
